#ifndef GAME_LAYER_HPP
#define GAME_LAYER_HPP

#include "xen/xen.hpp"
#include "scene.hpp"

using namespace Xen;

class GameLayer: public Layer {
public:
    GameLayer();
    ~GameLayer();

    void OnUpdate(TimeStep ts) override;
    void OnEvent(Event& e) override;

private:
    Texture2DLibrary texture2d_lib_;
    Ref<Model> basketball_;
    Ref<Model> ok_target_;
    Ref<Model> fail_target_;
    Ref<Model> brick_wall_;

    DirectLight dirlight_;
    DotLight dotlight_;
    SpotLight spotlight_;

    Ref<PerspectiveCameraController> controller_;
    Ref<OrthoCamera> ortho_camera_;

    glm::vec2 canva_size = {0, 0};

    Xen::Physical::World world_;
    Xen::Physical::Space space_;

    void initModels();
    void initCameras();
    void load2DResources();
    void initPhysical();

    class WelcomeScene: public Scene {
    public:
        WelcomeScene(GameLayer* layer);

        void OnUpdate(TimeStep& ts) override;
        void OnEvent(Event& e) override;

    private:
        int start_label_y_ = 100;
        bool start_label_y_increase_ = true;

        GameLayer* game_layer_ = nullptr;

        enum class GameMode {
            Welcome,
            Animation,
            Game
        };

        GameMode mode_ = GameMode::Welcome;

        void updateWelcome(TimeStep& ts);
        void eventWelcome(Event& e);
        
        void updateAnimation(TimeStep& ts);
        void eventAnimation(Event& e);

        void updateGame(TimeStep& ts);
        void eventGame(Event& e);
    };

    std::unique_ptr<WelcomeScene> welcome_scene_ = nullptr;
    Scene* scene_ = nullptr;
};

#endif
